#include "sActionHandlerPress.h"
#include "sComponentInstance.h"

namespace sgui
{
namespace inst
{
    
bool sActionHandlerPress::OnEvent(const obs::sEvent& event)
{
    switch (event.getID())
    {
        case obs::EVID_MOUSE_MOVE:
        {
            CAST_EVENT(m_ev, sMouseMoveEvent);
            getInstance()->setState(getActiveRect().pointIn(m_ev.m_position) ? CS_ACTIVE : CS_HOVER);
            return true;
        }
        case obs::EVID_MOUSE_RELEASE:
        {
            CAST_EVENT(m_ev, sMouseReleaseEvent);
            getInstance()->setState(getActiveRect().pointIn(m_ev.m_position) ? CS_HOVER : CS_NORMAL);

            if (getActiveRect().pointIn(m_ev.m_position))
            {
                sActionHandlerPressEvent ev;
                getInstance()->OnHandlerEvent(ev);
            }

            release(&m_ev);
            return true;
        }
    }
    return false;
}

sActionHandlerPress::sActionHandlerPress(sComponentInstance* instance, sComponentRectInstance *caller) :
    sActionHandler(instance, caller)
{
    instance->setState(CS_ACTIVE);
}
    
sActionHandlerPress::~sActionHandlerPress()
{
    getInstance()->setState(CS_NORMAL);
}

};
};